<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/


Route::namespace('Api')->name('api.')->group(function () {

    // 小程序登录
    Route::post('weapp/authorizations', 'AuthorizationsController@weappStore')
        ->name('weapp.authorizations.store');

    Route::middleware('auth:sanctum')->group(function () {
        //当前用户信息
        Route::get('/user', 'UserController@me')->name('user.me');
        //授权获取手机号
        Route::post('/user/getPhoneNumber', 'AuthorizationsController@getPhoneNumber')->name('user.getPhoneNumber');
        //修改当前用户信息
        Route::post('/user', 'UserController@store')->name('user.store');
        //留资
        Route::post('customerInfos', 'CustomerInfoController@store')->name('customerInfos.store');
        //我的留资
        Route::get('customerInfos', 'CustomerInfoController@index')->name('customerInfos.index');
        //待试驾预约数
        Route::get('customerInfos/count', 'CustomerInfoController@count');
        //修改留资
        Route::put('/customerInfos/{customerInfo}', 'CustomerInfoController@update')->name('customerInfos.update');
        //留资详情
        Route::get('/customerInfos/{customerInfo}', 'CustomerInfoController@show')->name('customerInfos.show');
        //获取试驾二维码
        Route::get('/customerInfos/{customerInfo}/driver', 'CustomerInfoController@driver')->name('customerInfos.driver');
        //活动抽奖
        Route::post('activities/{id}/draw', 'ActivityController@draw')->name('activities.draw');
        //填写收货地址
        Route::post('userDraws/{id}/address', ['as' => 'userDraws.address', 'uses' => 'UserDrawController@address']);
        //我的抽奖
        Route::get('userDraws', 'UserDrawController@index')->name('userDraws.index');
        //活动详情
        Route::get('activities/{id}', 'ActivityController@show')->name('activities.show');
        //卡券详情
        Route::get('userCoupons/{id}', 'UserCouponController@show');
        //埋点
        Route::post('eventRecords', 'EventRecordController@store');
        //申请成为推荐官
        Route::post('referees', 'RefereeController@store');
        //获取分享海报
        Route::get('referees/share', 'RefereeQrcodeController@show');
        //推荐官信息
        Route::get('referee', 'RefereeController@me');
        //邀请记录
        Route::get('referee/records', 'RefereeController@records');
    });

    //海报列表
    Route::get('banners', 'BannerController@index')->name('banners.index');
    //文本详情
    Route::get('articles/{sign}', 'ArticleController@show')->name('articles.show');
    //活动列表
    Route::get('activities', 'ActivityController@index')->name('activities.index');
    //所有的车型系列
    Route::get('vehicleSeries', 'VehicleSeriesController@index')->name('vehicleSeries.index');
    //车型列表
    Route::get('vehicles', 'VehicleController@index')->name('vehicle.index');
    //车型列表
    Route::get('vehicles/all', 'VehicleController@all')->name('vehicle.all');
    //车型详情
    Route::get('vehicles/{id}', 'VehicleController@show')->name('vehicles.show');
    //坐标换地址
    Route::get('map/geocoder', 'MapController@geocoder')->name('map.geocoder');
    //经销商列表
    Route::get('dealers', 'DealerController@index')->name('dealers.index');

    //开放平台接口
    Route::group(['prefix' => 'open', 'middleware' => 'sercet'], function () {
        Route::get('coupons', 'UserCouponController@getCouponByKey');
        Route::post('coupons/verify', 'UserCouponController@verify');
        Route::get('coupons/verify/records', 'UserCouponController@writeOffRecord');
        Route::post('generatescheme', 'WechatController@generatescheme');
        Route::get('clues', 'CustomerInfoController@getClueByKey');
        Route::post('clues/verify', 'CustomerInfoController@driverVerify');
        Route::get('dealer/drives', 'CustomerInfoController@drives');
        Route::get('cinfos', 'CustomerInfoController@list');
        Route::get('cinfos/all', 'CustomerInfoController@all');
        Route::get('cinfos/{id}', 'CustomerInfoController@default');
        Route::get('referees', 'RefereeController@list');
        Route::get('referees/all', 'RefereeController@all');
        Route::get('referees/{id}', 'RefereeController@default');
    });

    //兴趣爱好列表
    Route::get('interests', 'RefereeController@interests');
    //推荐官积分排行榜
    Route::get('referees/rank', 'RefereeController@rank');
});
